<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第16章：鼠标坐标与拖拽 | MarkDown的使用</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    
    <link rel="prev" href="../JavaScript/JavaScript_15.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.16"
        data-chapter-title="第16章：鼠标坐标与拖拽"
        data-filepath="JavaScript/JavaScript_16.md"
        data-basepath=".."
        data-revision="Sat Nov 10 2018 16:39:50 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="HTML/html_int.html">
            
                
                    <a href="../HTML/html_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        HTML5简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="HTML/gitbook_use.html">
            
                
                    <a href="../HTML/gitbook_use.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第0章：gitbook的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="HTML/lesson1.html">
            
                
                    <a href="../HTML/lesson1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        第1章：常用标签
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="HTML/lesson2.html">
            
                
                    <a href="../HTML/lesson2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第2章：列表与图片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="HTML/lesson3.html">
            
                
                    <a href="../HTML/lesson3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        第3章：表格与表单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="HTML/lesson4.html">
            
                
                    <a href="../HTML/lesson4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        第4章：实体字符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="HTML/lesson5.html">
            
                
                    <a href="../HTML/lesson5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        第5章：多媒体和iframe
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="CSS/css_int.html">
            
                
                    <a href="../CSS/css_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        CSS简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="CSS/css_1.html">
            
                
                    <a href="../CSS/css_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        第1章：引入css
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="CSS/css_2.html">
            
                
                    <a href="../CSS/css_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        第2章：选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="CSS/css_3.html">
            
                
                    <a href="../CSS/css_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        第3章：属性选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="CSS/css_4.html">
            
                
                    <a href="../CSS/css_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        第4章：伪类选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="CSS/css_5.html">
            
                
                    <a href="../CSS/css_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        第5章：盒子模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="CSS/css_6.html">
            
                
                    <a href="../CSS/css_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        第6章：伪对象选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="CSS/css_7.html">
            
                
                    <a href="../CSS/css_7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        第7章：font字体与边框
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="CSS/css_8.html">
            
                
                    <a href="../CSS/css_8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        第8章：行高
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="CSS/css_9.html">
            
                
                    <a href="../CSS/css_9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        第9章：文字与背景
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="CSS/css_10.html">
            
                
                    <a href="../CSS/css_10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        第10章：浮动
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="CSS/css_11.html">
            
                
                    <a href="../CSS/css_11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        第11章：定位与渐变
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="CSS/css_12.html">
            
                
                    <a href="../CSS/css_12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        第12章：css过渡与变形
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="CSS/css_13.html">
            
                
                    <a href="../CSS/css_13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.13.</b>
                        
                        第13章：css动画
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="CSS/css_14.html">
            
                
                    <a href="../CSS/css_14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.</b>
                        
                        第14章：css滤镜
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="CSS/css_15.html">
            
                
                    <a href="../CSS/css_15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.</b>
                        
                        第15章：swiper与地图插件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="CSS/css_16.html">
            
                
                    <a href="../CSS/css_16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.16.</b>
                        
                        第16章：移动端rem布局
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="CSS/css_17.html">
            
                
                    <a href="../CSS/css_17.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.17.</b>
                        
                        第17章：伸缩盒子
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="SASS/sass_int.html">
            
                
                    <a href="../SASS/sass_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        sass简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="SASS/sass_1.html">
            
                
                    <a href="../SASS/sass_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第1章：sass安装与使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="SASS/sass_2.html">
            
                
                    <a href="../SASS/sass_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第2章：sass语法入门
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Bootstrap/Bootstrap_int.html">
            
                
                    <a href="../Bootstrap/Bootstrap_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Bootstrap简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Bootstrap/Bootstrap_1.html">
            
                
                    <a href="../Bootstrap/Bootstrap_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第1章：Bootstrap
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="JavaScript/JavaScript_int.html">
            
                
                    <a href="../JavaScript/JavaScript_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        JavaScript简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="JavaScript/JavaScript_1.html">
            
                
                    <a href="../JavaScript/JavaScript_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第1章：JavaScript
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="JavaScript/JavaScript_2.html">
            
                
                    <a href="../JavaScript/JavaScript_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第2章：变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="JavaScript/JavaScript_3.html">
            
                
                    <a href="../JavaScript/JavaScript_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        第3章：Number
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="JavaScript/JavaScript_4.html">
            
                
                    <a href="../JavaScript/JavaScript_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        第4章：数据类型判断
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="JavaScript/JavaScript_5.html">
            
                
                    <a href="../JavaScript/JavaScript_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        第5章：运算符与字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="JavaScript/JavaScript_6.html">
            
                
                    <a href="../JavaScript/JavaScript_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        第6章：循环与流程控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="JavaScript/JavaScript_7.html">
            
                
                    <a href="../JavaScript/JavaScript_7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        第7章：函数与作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="JavaScript/JavaScript_8.html">
            
                
                    <a href="../JavaScript/JavaScript_8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        第8章：String方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="JavaScript/JavaScript_9.html">
            
                
                    <a href="../JavaScript/JavaScript_9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        第9章：数组方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="JavaScript/JavaScript_10.html">
            
                
                    <a href="../JavaScript/JavaScript_10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        第10章：定时器与排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="JavaScript/JavaScript_11.html">
            
                
                    <a href="../JavaScript/JavaScript_11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        第11章：Date与Math
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="JavaScript/JavaScript_12.html">
            
                
                    <a href="../JavaScript/JavaScript_12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        第12章：简单的DOM操作与垃圾回收
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.13" data-path="JavaScript/JavaScript_13.html">
            
                
                    <a href="../JavaScript/JavaScript_13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.13.</b>
                        
                        第13章：DOM操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.14" data-path="JavaScript/JavaScript_14.html">
            
                
                    <a href="../JavaScript/JavaScript_14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.14.</b>
                        
                        第14章：DOM修改样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.15" data-path="JavaScript/JavaScript_15.html">
            
                
                    <a href="../JavaScript/JavaScript_15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.15.</b>
                        
                        第15章：DOM常用标签属性
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.16" data-path="JavaScript/JavaScript_16.html">
            
                
                    <a href="../JavaScript/JavaScript_16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.16.</b>
                        
                        第16章：鼠标坐标与拖拽
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >MarkDown的使用</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x9F20;&#x6807;&#x5750;&#x6807;&#x4E0E;&#x62D6;&#x62FD;">&#x9F20;&#x6807;&#x5750;&#x6807;&#x4E0E;&#x62D6;&#x62FD;</h1>
<h3 id="&#x9F20;&#x6807;&#x7684;&#x5750;&#x6807;">&#x9F20;&#x6807;&#x7684;&#x5750;&#x6807;</h3>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;&#x540D;</th>
<th style="text-align:center">&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>clientX clientY</td>
<td style="text-align:center">&#x8DDF;&#x5F53;&#x524D;&#x7A97;&#x53E3;&#x4F4D;&#x7F6E;&#xFF08;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#xFF09;&#x6709;&#x5173;&#xFF08;&#x6EDA;&#x52A8;&#x6761;&#x53EF;&#x4EE5;&#x663E;&#x793A;&#x5DEE;&#x522B;&#xFF09;</td>
</tr>
<tr>
<td>layerX layerY</td>
<td style="text-align:center">&#x6B63;&#x5E38;&#x6D41;&#xFF1A;&#x5F53;&#x524D;&#x5143;&#x7D20;&#x7684;&#x504F;&#x79FB;&#x52A0;&#x4E0A;&#x9F20;&#x6807;&#x5728;&#x5143;&#x7D20;&#x5185;&#x7684;&#x504F;&#x79FB;;&#x8131;&#x79BB;&#x6587;&#x6863;&#x6D41;&#xFF1A;&#x548C;offset&#x7684;&#x4F4D;&#x7F6E;&#x76F8;&#x8FD1;</td>
</tr>
<tr>
<td>offsetX offsetY</td>
<td style="text-align:center">&#x76F8;&#x5BF9;&#x76D1;&#x542C;&#x5143;&#x7D20;&#x7684;&#x5185;&#x90E8;&#x5750;&#x6807;</td>
</tr>
<tr>
<td>pageX pageY</td>
<td style="text-align:center">&#x53EA;&#x8DDF;&#x9875;&#x9762;&#x7684;&#x539F;&#x5C3A;&#x5BF8;&#x6709;&#x5173;</td>
</tr>
<tr>
<td>screenX screenY</td>
<td style="text-align:center">&#x76F8;&#x5BF9;&#x5C4F;&#x5E55;&#x7684;&#x4F4D;&#x7F6E;</td>
</tr>
</tbody>
</table>
<pre><code>
    &lt;!DOCTYPE html&gt;
    &lt;html&gt;
        &lt;head&gt;
            &lt;meta charset=&quot;UTF-8&quot;&gt;
            &lt;title&gt;&#x9F20;&#x6807;&#x5750;&#x6807;&lt;/title&gt;
            &lt;style type=&quot;text/css&quot;&gt;
                *{
                    margin: 0;
                    padding: 0;
                }
                html,body{
                    width: 100%;
                    height: 100%;
                    position: relative;
                }
                .box{
                    /*margin-top: 150px;
                    margin-left: 200px;*/
                    width: 100px;
                    height: 100px;
                    background-color: skyblue;
                    color: white;
                    line-height: 100px;
                    text-align: center;
                    position: absolute;
                }
            &lt;/style&gt;
        &lt;/head&gt;
        &lt;body&gt;

            &lt;div class=&quot;box&quot;&gt;&lt;/div&gt;



            &lt;script type=&quot;text/javascript&quot;&gt;
                var box = document.querySelector(&quot;.box&quot;);
                box.addEventListener(&quot;click&quot;,function(e){
                    //console.log(e)
                    // clientX clientY    &#x8DDF;&#x5F53;&#x524D;&#x7A97;&#x53E3;&#x4F4D;&#x7F6E;&#xFF08;&#x53EF;&#x89C6;&#x533A;&#x57DF;&#xFF09;&#x6709;&#x5173;&#xFF08;&#x6EDA;&#x52A8;&#x6761;&#x53EF;&#x4EE5;&#x663E;&#x793A;&#x5DEE;&#x522B;&#xFF09;
                    console.log(&quot;client&quot;,e.clientX,e.clientY)

                    // layerX layerY    
                    // &#x6B63;&#x5E38;&#x6D41;&#xFF1A;&#x5F53;&#x524D;&#x5143;&#x7D20;&#x7684;&#x504F;&#x79FB;&#x52A0;&#x4E0A;&#x9F20;&#x6807;&#x5728;&#x5143;&#x7D20;&#x5185;&#x7684;&#x504F;&#x79FB;
                    // &#x8131;&#x79BB;&#x6587;&#x6863;&#x6D41;&#xFF1A;&#x548C;offset&#x7684;&#x4F4D;&#x7F6E;&#x76F8;&#x8FD1;
                    console.log(&quot;layer&quot;,e.layerX,e.layerY)

                    // offsetX offsetY    &#x76F8;&#x5BF9;&#x76D1;&#x542C;&#x5143;&#x7D20;&#x7684;&#x5185;&#x90E8;&#x5750;&#x6807;
                    //console.log(&quot;offset&quot;,e.offsetX,e.offsetY)

                    // pageX pageY    &#x53EA;&#x8DDF;&#x9875;&#x9762;&#x7684;&#x539F;&#x5C3A;&#x5BF8;&#x6709;&#x5173;
                    console.log(&quot;page&quot;,e.pageX,e.pageY)

                    // screenX screenY    &#x76F8;&#x5BF9;&#x5C4F;&#x5E55;&#x7684;&#x4F4D;&#x7F6E;
                    //console.log(&quot;screen&quot;,e.screenX,e.screenY)


                    //console.log( box.offsetLeft , box.offsetTop )





                    /************************************
                        offsetX &#x7684;&#x517C;&#x5BB9;&#x6027;&#x95EE;&#x9898;
                    ************************************/

                    // &#x5982;&#x679C;e.offsetX&#x4E0D;&#x652F;&#x6301;&#xFF0C;&#x503C;&#x4E3A;undefined&#xFF0C;&#x90A3;&#x4E48;&#x4F7F;&#x7528;&#x517C;&#x5BB9;&#x6027;&#x597D;&#x7684;&#x65B9;&#x6CD5; e.pageX - div.offsetLeft
                    var offsetX = e.offsetX || e.pageX - div.offsetLeft;

                    // &#x4E0E;&#x4E0B;&#x9762;&#x7684;&#x65B9;&#x6CD5;&#x6548;&#x679C;&#x4E00;&#x81F4;
                    var offsetX;
                    if( e.offsetX != undefined ){
                        offsetX = e.offsetX;
                    }else{
                        offsetX = e.pageX - div.offsetLeft;
                    }
                })

                // &#x7269;&#x4F53;&#x8DDF;&#x968F;&#x9F20;&#x6807;&#x79FB;&#x52A8;
                document.body.addEventListener(&quot;mousemove&quot;,function(e){
                    console.log(e.pageX,e.pageY)
                    box.style.top = e.pageY - (box.offsetHeight/2) + &quot;px&quot;;
                    box.style.left = e.pageX - (box.offsetWidth/2) + &quot;px&quot;;
                    console.log(box.style.left,box.style.top)
                })

            &lt;/script&gt;
        &lt;/body&gt;
    &lt;/html&gt;
</code></pre><h3 id="&#x5143;&#x7D20;&#x7684;&#x62D6;&#x62FD;&#x5C5E;&#x6027;">&#x5143;&#x7D20;&#x7684;&#x62D6;&#x62FD;&#x5C5E;&#x6027;</h3>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;&#x540D;</th>
<th style="text-align:center">&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>draggable</td>
<td style="text-align:center">&#x5728;html&#x6807;&#x7B7E;&#x4E2D;&#x4F7F;&#x7528;&#xFF0C;&#x503C;&#x4E3A;&#x5E03;&#x5C14;&#x503C;</td>
</tr>
<tr>
<td>dragend</td>
<td style="text-align:center">&#x62D6;&#x62FD;&#x7ED3;&#x675F;&#x65F6;&#x89E6;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;</td>
</tr>
<tr>
<td>touchstart</td>
<td style="text-align:center">&#x79FB;&#x52A8;&#x7AEF;&#xFF0C;&#x7B2C;&#x4E00;&#x6B21;&#x7684;&#x5750;&#x6807;</td>
</tr>
<tr>
<td>touchmove</td>
<td style="text-align:center">&#x79FB;&#x52A8;&#x7AEF;&#xFF0C;&#x79FB;&#x52A8;&#x7684;&#x5750;&#x6807;</td>
</tr>
<tr>
<td>touchend</td>
<td style="text-align:center">&#x79FB;&#x52A8;&#x7AEF;&#xFF0C;&#x677E;&#x624B;&#x7684;&#x5750;&#x6807;</td>
</tr>
<tr>
<td>offsetWidth</td>
<td style="text-align:center">&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x5BF9;&#x8C61;&#x7684;padding+border+contentwidth&#x5C5E;&#x6027;&#x503C;&#x4E4B;&#x548C;</td>
</tr>
<tr>
<td>offsetHeight</td>
<td style="text-align:center">&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x5BF9;&#x8C61;&#x7684;padding+border+contentheight&#x5C5E;&#x6027;&#x503C;&#x4E4B;&#x548C;</td>
</tr>
</tbody>
</table>
<pre><code>
    &lt;div class=&quot;box&quot; draggable=&quot;true&quot;&gt;&lt;/div&gt;


    &lt;script type=&quot;text/javascript&quot;&gt;

        var box = document.querySelector(&quot;.box&quot;);

        box.addEventListener(&quot;dragend&quot;,function(e){
            console.log(e.pageX,e.pageY)
            box.style.left = e.pageX - (box.offsetWidth/2) + &quot;px&quot;;
            box.style.top = e.pageY - (box.offsetHeight/2) + &quot;px&quot;;
        })

        // touchstart        touchmove        touchend
        // &#x7B2C;&#x4E00;&#x6B21;&#x5750;&#x6807;        &#x79FB;&#x52A8;&#x7684;&#x5750;&#x6807;        &#x677E;&#x624B;&#x7684;&#x5750;&#x6807;
        box.addEventListener(&quot;touchstart&quot;,function(){
            // &#x62D6;&#x62FD;&#x5F00;&#x59CB;,&#x6253;&#x5F00;&#x5F00;&#x5173;
            box.flag = true;
        })

        box.addEventListener(&quot;touchmove&quot;,function(e){
            console.log(e)
            // &#x624B;&#x6307;&#x7684;&#x4F4D;&#x7F6E;
            var handX = e.changedTouches[0].pageX;
            var handY = e.changedTouches[0].pageY;

            box.style.left = handX - (box.offsetWidth/2) + &quot;px&quot;;
            box.style.top = handY - (box.offsetHeight/2) + &quot;px&quot;;
        })

        box.addEventListener(&quot;touchend&quot;,function(){
            // &#x62D6;&#x62FD;&#x5F00;&#x59CB;,&#x6253;&#x5F00;&#x5F00;&#x5173;
            box.flag = false;
        })
    &lt;/script&gt;
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../JavaScript/JavaScript_15.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 第15章：DOM常用标签属性"><i class="fa fa-angle-left"></i></a>
        
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
